﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TransformCost.Question;

namespace TransformCost.Answer
{
    class Sofia : ITransformCost
    {
        public int GetMinExchanges(int[] source, int[] target)
        {
            //throw new NotImplementedException();
            int Asteps=0, Bsteps=0;
            for (int i = 0; i < source.Length; i++)
            {
                int tNum = NumSearch(target, source[i])-i;
                if (tNum > 0) Asteps += tNum;
                else Bsteps += tNum;
            }
            if (Asteps + Bsteps == 0) return Asteps;
            else return Math.Min(Asteps,-Bsteps);
        }

        public int NumSearch(int[] arr, int value)
        {
            int index = 0;
            for (; index < arr.Length; index++)
            {
                if (arr[index] == value)
                {
                    break;
                }
            }
            return index;
        }
    }
}

